Ext.define('appmod.view.resources.module.Dashboard', {
    extend: 'Ext.panel.Panel',
    alias: [
		'widget.module-dashboard',
		'widget.module.dashbaord'
	],
    requires: [
		'Ext.ux.CheckColumn',
		'Ext.selection.CellModel'
		],
    layout: {
        type: 'border'
    },
    
    initComponent: function(){

        var me = this;

        Ext.applyIf(me, {
            items: [{
                xtype: 'gridpanel',
                padding: '5 0 5 5',
                title: '已加载模块',
                region: 'center',
                columns: [{
                    xtype: 'gridcolumn',
                    dataIndex: 'name',
                    width: 250,
                    text: '名 称',
                    sortable: false
                }, {
                    xtype: 'gridcolumn',
                    dataIndex: 'vender',
                    width: 250,
                    text: '厂商/作者',
                    sortable: false
                }, {
                    xtype: 'gridcolumn',
                    dataIndex: 'version',
                    width: 100,
                    text: '版本',
                    sortable: false
                }, {
                    xtype: 'datecolumn',
                    dataIndex: 'releaseDate',
                    text: '发布日期',
                    width: 150,
                    format: 'Y-m-d',
                    sortable: false
                }, {
                    xtype: 'booleancolumn',
                    dataIndex: 'disabled',
                    sortable: false,
                    width: 100,
                    text: '状态',
                    trueText: '禁用',
                    falseText: '启用'
                }, {
                    xtype: 'actioncolumn',
                    width: 50,
                    items: [{
                        getClass: function(v, meta, rec){
                            var disabled = rec.get('disabled');
                            if (disabled) {
								this.items[0].tooltip = '启用该模块';
                                return 'disconnect';
                            }
                            else {
								this.items[0].tooltip = '禁用该模块';
                                return 'connect';
                            }
                        },
                        handler: function(grid, rowIndex, colIndex){
							
                            var rec = grid.getStore().getAt(rowIndex);
                            var disabled = rec.get('disabled');
                            var resId = rec.getId();
                            var moduleCode = rec.get('code');
                            var url = null;
                            var jsonObjs = {
                                resId: resId,
                                moduleId: moduleCode
                            }
                            if ( disabled ) {
                                url = '../../data/resource/resources/unableModule.json'
                            }
                            else {
                                url = '../../data/resource/resources/enableModule.json'
                            }
                            
                            try {
                                Ext.Ajax.request({
                                    url: url,
                                    method: 'post',
                                    params: {
                                        'jsonData': Ext.encode(jsonObjs)
                                    },
                                    success: function(response, opts){
                                    
                                        var obj = Ext.decode(response.responseText);
                                        
                                        // --- popup message ---
                                        Ext.MessageBox.show({
                                            title: "提示",
                                            msg: obj.msg,
                                            buttons: Ext.MessageBox.OK,
                                            icon: Ext.MessageBox.WARNING
                                        });
                                    },
                                    failure: function(response, opts){
                                    
                                    }
                                });
                            } 
                            catch (e) {
                                alert(e);
                            }
                            
                            
                        }
                    },{
						action:'flashSubFunction',
						iconCls:'x-action-edittask',
						tooltip:'刷新子功能',
                        handler: function(grid, rowIndex, colIndex , item , e ,record) {
							
							me.fireEvent("reflashModuleFunctions",grid, {
								grid:grid,
								rowIndex : rowIndex,
								colIndex : colIndex,
								item:item,
								event:e,
								record:record
							})


                        }

                    }]
                }],
                viewConfig: {},
                dockedItems: [{
                    xtype: 'toolbar',
                    dock: 'top',
                    layout: {
                        pack: 'left'
                    },
                    items: [{
						iconCls:'x-action-add',
                        minWidth: 80,
                        text: '加载模块',
						action:'loadModule'
                    }]
                }]				
            
            }, {
                xtype: 'gridpanel',
                padding: '5 5 5 0',
                width: 300,
                title: '支持功能',
                region: 'east',
                split: true,
                columns: [{
                    xtype: 'gridcolumn',
                    dataIndex: 'name',
                    width: 180,
                    text: '功能名称',
                    sortable: false
                },{
					sortable: false,
					header:'是否启用 ',
					dataIndex:'disabled',
					width:60,
					editor:{
						xtype:'combobox',
						typeAhead:true,
						editable :false,
						value:false,
						triggerAction:'all',
						selectOnTab:true,
						displayField: 'name',
						valueField:'value',
                		store: Ext.create('Ext.data.ArrayStore', {
							storeId:'selectId',
							fields:['name' , 'value'],
							data:[
								['启用',true],
								['禁止',false]
							]
						}),						
						queryMode: 'local',
                		listClass: 'x-combo-list-small'
					},
					renderer:function(value) {
						
						if ( !value ) {
							//  value = 0
							return '启用';
						} else {
							// value = 1
							return '禁用';
						}
					}
					
				}],
				plugins:[
					Ext.create('Ext.grid.plugin.CellEditing', {
			        	clicksToEdit: 2
    				})
				],
				selModel: {
					selType:'cellmodel'
				},
                viewConfig: {},
                dockedItems: [{
                    xtype: 'toolbar',
                    dock: 'top',
                    layout: {
                        pack: 'left'
                    },
                    items: [
					/*{
                        minWidth: 80,
                        text: '功能明细',
						action:'viewFunDetail'
                    }, 
                    */
					{
                        minWidth: 80,
                        text: '更新功能',
						action:'updateFunBootup'
                    }]
                }]
            }]
        });

        
        me.callParent(arguments);

		var modulePanel = me.down('gridpanel[region=center]');
		modulePanel.addEvents('reflashModuleFunctions');


    },
	
	
	initFunctionListStore:function() {
		

	}
	
});
